<template>
	<view>
		<view v-if="isHide">
		    <view>
		        <view class='header'>
		            <view class='myicon icon-weixin' style="font-size: 60px;color: #1aad19;"></view>
		        </view>
		 
		        <view class='content'>
		            <view>申请获取以下权限</view>
		            <text>获得你的公开信息(昵称，头像等)</text>
		        </view>
				
				<input type="nickname" placeholder="请输入昵称"/>

		 
		        <button v-if="!user_info" class='bottom' type='primary' open-type="chooseAvatar" lang="zh_CN" @bindchooseavatar="bindchooseavatar">
		            授权登录
		        </button>
				
				<button v-if="user_info&&!user_info.tel" class='bottom' type='primary' open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="get_tel">
				    授权手机号
				</button>
				
		    </view>
		</view>
		 
		<view v-else>
		    <view>我的首页内容</view>
		</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isHide:true,
				return_url:null,
				user_info:null,
			}
		},
		onLoad(options) {
			if(options.return_url){
				this.return_url=options.return_url;
			}
		},
		methods: {
			get_tel(e){
				uni.login({
				  provider: 'weixin',
				  success:  (loginRes)=> {
				    console.log('loginRes',loginRes);
					let wx_code=loginRes.code;
					
					this.get('/wechat/get_tel',{encryptedData:e.detail.encryptedData,code:wx_code,iv:e.detail.iv}).then(({code})=>{
						if(code===1){
							
						}
					})
				  }
				});
			},
			login(){
				let share_id = uni.getStorageSync('share_id');
				uni.login({
				  provider: 'weixin',
				  success:  (loginRes)=> {
					  console.log(888,loginRes)
					let wx_code=loginRes.code;
					uni.getUserProfile({
					  desc: '用于完善您的资料', 
					  lang: 'ch',
					  success: (res) => {
						  // console.log('getUserProfile',res)
						  this.get('/index/xcx_login',{
						  		encryptedData:res.encryptedData,
								iv:res.iv,
								code:wx_code,
								latitude:uni.getStorageSync('latitude'),
								longitude:uni.getStorageSync('longitude'),
								signature:res.signature,
								share_id:share_id?share_id:0,
						  	}).then(({code})=>{
						  	if(code===1){
						  		
						  	}
						  })
					  }
					})
					
				  }
				});
			}
		}
	}
</script>

<style>
.header {
    margin: 90rpx 0 90rpx 50rpx;
    border-bottom: 1px solid #ccc;
    text-align: center;
    width: 650rpx;
    height: 300rpx;
    line-height: 450rpx;
}
 
.header image {
    width: 200rpx;
    height: 200rpx;
}
 
.content {
    margin-left: 50rpx;
    margin-bottom: 90rpx;
}
 
.content text {
    display: block;
    color: #9d9d9d;
    margin-top: 40rpx;
}
 
.bottom {
    border-radius: 80rpx;
    margin: 70rpx 50rpx;
    font-size: 35rpx;
}

</style>
